package com.bwei.like.mynewstop.adapater;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwei.like.mynewstop.R;
import com.bwei.like.mynewstop.base.MyBaseAdapater;
import com.bwei.like.mynewstop.utils.CommonUtils;

import java.util.ArrayList;

/**
 * Created by LiKe on 2016/11/5.
 */
public class Menu_ListView_Adapater extends MyBaseAdapater<Integer> {

    private int[] titles = {R.string.haoyou, R.string.huati, R.string.shoucang, R.string.huodong, R.string.shangcheng, R.string.fankui, R.string.baoliao};

    public Menu_ListView_Adapater(ArrayList arrayList, Context context) {
        super(arrayList, context);
    }

    @Override
    public View initView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = CommonUtils.inflter(R.layout.menu_listview_item);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.menuimage.setImageResource(arrayList.get(position));
        viewHolder.menuTextview.setText(titles[position]);
        return convertView;
    }

    public class ViewHolder {
        public final ImageView menuimage;
        public final TextView menuTextview;
        public final View root;

        public ViewHolder(View root) {
            menuimage = (ImageView) root.findViewById(R.id.menu_image);
            menuTextview = (TextView) root.findViewById(R.id.menu_textview);
            this.root = root;
        }
    }
}
